




"""客户增加开票信息"""

from odoo import models, api, fields
from odoo.tools import float_compare
from odoo.exceptions import UserError, ValidationError


class Partner(models.Model):
    _inherit = 'res.partner'

    nd_invoice_info_ids = fields.One2many('nd.invoice.info', 'partner_id', string="开票信息")


class TaxTicketType(models.Model):
    #information for invoice
    _name = "nd.invoice.info"
    _description = '开票信息'

    partner_id = fields.Many2one('res.partner', '客户')
    name = fields.Char('开票公司', required=True)
    vat_number = fields.Char('增值税号', required=True)
    opening_bank = fields.Char('开户行', required=True)
    tax_registration_address = fields.Char('税务注册地址')
    phone = fields.Char('开票电话')
    zip_code = fields.Char('邮编')
    description = fields.Text('备注')
    customer_invoice_bank_account = fields.Char('银行账户', required=True)

    @api.constrains('customer_invoice_bank_account', 'vat_number')
    def _no_whitespace(self):
        for order in self:
            if order.customer_invoice_bank_account:
                if order.customer_invoice_bank_account and ' ' in order.customer_invoice_bank_account.rstrip():
                    raise ValidationError('银行账号中不能有空格！')
                if order.vat_number and ' ' in order.vat_number.rstrip():
                    raise ValidationError('增值税号中不能有空格！')
